package com.celan.year2023.month05.day17;

/**
 * @author Celan
 * @description TODO
 */
public class Solution {
    public int maxProduct(String[] words) {
        int n = words.length, idx = 0;
        //状态压缩
        int[] masks = new int[n];
        for (String word : words) {
            int t = 0;
            for (int i = 0; i < word.length(); i++) {
                //与a的偏移值
                int u = word.charAt(i) - 'a';
                t |= (1 << u);
            }
            masks[idx++] = t;
        }
        //masks此时记录了所有单词的字母出现频率
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if ((masks[i] & masks[j]) == 0) {
                    //说明两个单词没有字母重复
                    ans = Math.max(ans, words[i].length() * words[j].length());
                }
            }
        }
        return ans;
    }
}
